package com.rh.controller;

import com.rh.entity.EduComment;
import com.rh.result.ResultVo;
import com.rh.service.EduCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 评论 前端控制器
 * @author rh
 */
@RestController
@RequestMapping("/educenter/comment")
@Api(tags = "评论管理")
@CrossOrigin
public class EduCommentController {
    @Autowired
    private EduCommentService eduCommentService;

    /**
     * 根据课程id分页查询课程评论的方法
     */
    @ApiOperation(value = "1.根据课程id查询评论(分页)")
    @GetMapping("getCommentPage/{page}/{limit}")
    public ResultVo getCommentPage(@PathVariable long page,
                                   @PathVariable long limit,
                                   String courseId){

        Map<String, Object> commentPageList = eduCommentService.getCommentPageList(page, limit, courseId);
        return ResultVo.ok().data(commentPageList);
    }
    /**
     * 添加评论
     */
    @ApiOperation(value = "2.添加评论")
    @PostMapping("/auth/addComment")
    public ResultVo insertComment(HttpServletRequest request, @RequestBody EduComment eduComment){
        int i=eduCommentService.addComment(request,eduComment);
        if(i<=0){
            return ResultVo.error();
        }
        return ResultVo.ok();
    }
}

